package main

import (
	"gin-learn/010-swagger/docs"
	"net/http"
	"time"

	"github.com/gin-gonic/gin"
	ginSwagger "github.com/swaggo/gin-swagger"

	swaggerfiles "github.com/swaggo/files"
)

// 0.在项目中使用swag init,初始化swagger配置文件

// swagger 访问的url
// http://localhost:8080/swagger/index.html
func main() {

	eng := gin.Default()
	//1.说明 api的前缀信息
	docs.SwaggerInfo.BasePath = "/api/v1"

	v1 := eng.Group("/api/v1")
	v1.GET("/ping", Pong)

	//2.说明 swagger的访问路径
	eng.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))

	eng.Run(":8080")

}

// @BasePath /api/v1

// @Summary Ping 测试接口
// @Description Ping 测试接口
// @Tags Ping
// @Accept  json
// @Produce  json
// @Success 200 {object} map[string]interface{}
// @Router /ping [get]
func Pong(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{
		"message": "pong",
		"time":    time.Now().Format("2006-01-02 15:04:05"),
	})
}
